<template>
  <div class="app-container">
    <div class="search-container">
      <el-form v-show="showSearch" ref="queryParamsRef" :inline="true" :model="queryParams" label-width="100px">
        <el-form-item label="采购计划主表id" prop="drugPurchasingPlanId">
          <el-input
            v-model="queryParams.drugPurchasingPlanId"
            clearable
            placeholder="请输入采购计划主表id"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="序号" prop="itemNo">
          <el-input
            v-model="queryParams.itemNo"
            clearable
            placeholder="请输入序号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="药品编码" prop="drugCode">
          <el-input
            v-model="queryParams.drugCode"
            clearable
            placeholder="请输入药品编码"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="药品字典drug_info id" prop="drugInfoId">
          <el-input
            v-model="queryParams.drugInfoId"
            clearable
            placeholder="请输入药品字典drug_info id"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="包装数量" prop="packageNum">
          <el-input
            v-model="queryParams.packageNum"
            clearable
            placeholder="请输入包装数量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="包装规格" prop="packageSpec">
          <el-input
            v-model="queryParams.packageSpec"
            clearable
            placeholder="请输入包装规格"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="包装单位" prop="packageUnits">
          <el-select v-model="queryParams.packageUnits" clearable placeholder="请选择包装单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="最小规格" prop="minSpec">
          <el-input
            v-model="queryParams.minSpec"
            clearable
            placeholder="请输入最小规格"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="最小单位" prop="minUnits">
          <el-select v-model="queryParams.minUnits" clearable placeholder="请选择最小单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="大小包装：1(小包装)；2(大包装)" prop="packSize">
          <el-input
            v-model="queryParams.packSize"
            clearable
            placeholder="请输入大小包装：1(小包装)；2(大包装)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="进货价(批量入库的入库价,发放出库的零售价)" prop="tradePrice">
          <el-input
            v-model="queryParams.tradePrice"
            clearable
            placeholder="请输入进货价(批量入库的入库价,发放出库的零售价)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="零售价" prop="retailPrice">
          <el-input
            v-model="queryParams.retailPrice"
            clearable
            placeholder="请输入零售价"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="批号" prop="batchNo">
          <el-input
            v-model="queryParams.batchNo"
            clearable
            placeholder="请输入批号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="生产日期" prop="produceDate">
          <el-date-picker v-model="queryParams.produceDate"
                          clearable
                          placeholder="请选择生产日期"
                          type="date"
                          value-format="YYYY-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-date-picker v-model="queryParams.expireDate"
                          clearable
                          placeholder="请选择有效期"
                          type="date"
                          value-format="YYYY-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="小包装库存量" prop="quantity">
          <el-input
            v-model="queryParams.quantity"
            clearable
            placeholder="请输入小包装库存量"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="机构ID" prop="orgId">
          <el-input
            v-model="queryParams.orgId"
            clearable
            placeholder="请输入机构ID"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="货位" prop="location">
          <el-input
            v-model="queryParams.location"
            clearable
            placeholder="请输入货位"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建时间" prop="invoiceDate">
          <el-date-picker v-model="queryParams.invoiceDate"
                          clearable
                          placeholder="请选择创建时间"
                          type="date"
                          value-format="YYYY-MM-DD">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注信息" prop="remarks">
          <el-input
            v-model="queryParams.remarks"
            clearable
            placeholder="请输入备注信息"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="比例" prop="proportion">
          <el-input
            v-model="queryParams.proportion"
            clearable
            placeholder="请输入比例"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="进价(小规格)" prop="tradePriceMin">
          <el-input
            v-model="queryParams.tradePriceMin"
            clearable
            placeholder="请输入进价(小规格)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="进价(小规格)" prop="retailPriceMin">
          <el-input
            v-model="queryParams.retailPriceMin"
            clearable
            placeholder="请输入进价(小规格)"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="创建人姓名" prop="createByName">
          <el-input
            v-model="queryParams.createByName"
            clearable
            placeholder="请输入创建人姓名"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="修改人姓名" prop="updateByName">
          <el-input
            v-model="queryParams.updateByName"
            clearable
            placeholder="请输入修改人姓名"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="采购计划单号" prop="purchasingPlanNo">
          <el-input
            v-model="queryParams.purchasingPlanNo"
            clearable
            placeholder="请输入采购计划单号"
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item label="是否国采Y是 N否" prop="isNationalProcurement">
          <el-select v-model="queryParams.isNationalProcurement" clearable placeholder="请选择是否国采Y是 N否">
            <el-option
              v-for="dict in dictDataMap['sys_yes_no']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <query-form-button @handleQuery="handleQuery" @resetQuery="resetQuery"/>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['drug:drugPurchasingPlanItem:add']"
          plain
          type="primary"
          @click="handleAdd"
        >
          <template
            #icon>
            <i-ep-plus/>
          </template>
          新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['drug:drugPurchasingPlanItem:edit']"
          :disabled="single"
          plain
          type="success"
          @click="handleUpdate"
        >
          <template #icon>
            <i-ep-edit/>
          </template>
          修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['drug:drugPurchasingPlanItem:remove']"
          :disabled="multiple"
          plain
          type="danger"
          @click="handleDelete"
        >
          <template #icon>
            <i-ep-delete/>
          </template>
          删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          v-hasPerm="['drug:drugPurchasingPlanItem:export']"
          plain
          type="warning"
          @click="handleExport"
        >
          <template #icon>
            <i-ep-download/>
          </template>
          导出
        </el-button>
      </el-col>
    </el-row>

    <el-table v-adaptive :border="true" :data="drugPurchasingPlanItemList" :header-cell-style="$headerCellStyle"
              :stripe="true" highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column :align="'center'" type="selection" width="55"/>
      <el-table-column v-if="true" :align="'center'" label="主键" prop="id"/>
      <el-table-column :align="'center'" label="采购计划主表id" prop="drugPurchasingPlanId"/>
      <el-table-column :align="'center'" label="序号" prop="itemNo"/>
      <el-table-column :align="'center'" label="药品编码" prop="drugCode"/>
      <el-table-column :align="'center'" label="药品字典drug_info id" prop="drugInfoId"/>
      <el-table-column :align="'center'" label="包装数量" prop="packageNum"/>
      <el-table-column :align="'center'" label="包装规格" prop="packageSpec"/>
      <el-table-column :align="'center'" label="包装单位" prop="packageUnits">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['spec_unit']" :value="scope.row.packageUnits"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="最小规格" prop="minSpec"/>
      <el-table-column :align="'center'" label="最小单位" prop="minUnits">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['spec_unit']" :value="scope.row.minUnits"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="大小包装：1(小包装)；2(大包装)" prop="packSize"/>
      <el-table-column :align="'center'" label="进货价(批量入库的入库价,发放出库的零售价)" prop="tradePrice"/>
      <el-table-column :align="'center'" label="零售价" prop="retailPrice"/>
      <el-table-column :align="'center'" label="批号" prop="batchNo"/>
      <el-table-column :align="'center'" label="生产日期" prop="produceDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.produceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="有效期" prop="expireDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.expireDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="小包装库存量" prop="quantity"/>
      <el-table-column :align="'center'" label="机构ID" prop="orgId"/>
      <el-table-column :align="'center'" label="货位" prop="location"/>
      <el-table-column :align="'center'" label="创建时间" prop="invoiceDate" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.invoiceDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" label="备注信息" prop="remarks"/>
      <el-table-column :align="'center'" label="比例" prop="proportion"/>
      <el-table-column :align="'center'" label="进价(小规格)" prop="tradePriceMin"/>
      <el-table-column :align="'center'" label="进价(小规格)" prop="retailPriceMin"/>
      <el-table-column :align="'center'" label="创建人姓名" prop="createByName"/>
      <el-table-column :align="'center'" label="修改人姓名" prop="updateByName"/>
      <el-table-column :align="'center'" label="采购计划单号" prop="purchasingPlanNo"/>
      <el-table-column :align="'center'" label="是否国采Y是 N否" prop="isNationalProcurement">
        <template #default="scope">
          <dict-data-tag :options="dictDataMap['sys_yes_no']" :value="scope.row.isNationalProcurement"/>
        </template>
      </el-table-column>
      <el-table-column :align="'center'" class-name="small-padding fixed-width" label="操作" width="220">
        <template #default="scope">
          <el-button
            v-hasPerm="['drug:drugPurchasingPlanItem:edit']"
            type="success"
            @click="handleUpdate(scope.row)"
          >
            <template #icon>
              <i-ep-edit/>
            </template>
            修改
          </el-button>
          <el-button
            v-hasPerm="['drug:drugPurchasingPlanItem:remove']"
            type="danger"
            @click="handleDelete(scope.row)"
          >
            <template #icon>
              <i-ep-delete/>
            </template>
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      v-model:limit="queryParams.pageSize"
      v-model:page="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改药品采购计划确认明细对话框 -->
    <el-dialog v-model="open" :close-on-click-modal="false" :title="title" append-to-body width="500px">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="采购计划主表id" prop="drugPurchasingPlanId">
          <el-input v-model="form.drugPurchasingPlanId" placeholder="请输入采购计划主表id"/>
        </el-form-item>
        <el-form-item label="序号" prop="itemNo">
          <el-input v-model="form.itemNo" placeholder="请输入序号"/>
        </el-form-item>
        <el-form-item label="药品编码" prop="drugCode">
          <el-input v-model="form.drugCode" placeholder="请输入药品编码"/>
        </el-form-item>
        <el-form-item label="药品字典drug_info id" prop="drugInfoId">
          <el-input v-model="form.drugInfoId" placeholder="请输入药品字典drug_info id"/>
        </el-form-item>
        <el-form-item label="包装数量" prop="packageNum">
          <el-input v-model="form.packageNum" placeholder="请输入包装数量"/>
        </el-form-item>
        <el-form-item label="包装规格" prop="packageSpec">
          <el-input v-model="form.packageSpec" placeholder="请输入包装规格"/>
        </el-form-item>
        <el-form-item label="包装单位" prop="packageUnits">
          <el-select v-model="form.packageUnits" placeholder="请选择包装单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最小规格" prop="minSpec">
          <el-input v-model="form.minSpec" placeholder="请输入最小规格"/>
        </el-form-item>
        <el-form-item label="最小单位" prop="minUnits">
          <el-select v-model="form.minUnits" placeholder="请选择最小单位">
            <el-option
              v-for="dict in dictDataMap['spec_unit']"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="大小包装：1(小包装)；2(大包装)" prop="packSize">
          <el-input v-model="form.packSize" placeholder="请输入大小包装：1(小包装)；2(大包装)"/>
        </el-form-item>
        <el-form-item label="进货价(批量入库的入库价,发放出库的零售价)" prop="tradePrice">
          <el-input v-model="form.tradePrice" placeholder="请输入进货价(批量入库的入库价,发放出库的零售价)"/>
        </el-form-item>
        <el-form-item label="零售价" prop="retailPrice">
          <el-input v-model="form.retailPrice" placeholder="请输入零售价"/>
        </el-form-item>
        <el-form-item label="批号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入批号"/>
        </el-form-item>
        <el-form-item label="生产日期" prop="produceDate">
          <el-date-picker v-model="form.produceDate"
                          clearable
                          placeholder="请选择生产日期"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="有效期" prop="expireDate">
          <el-date-picker v-model="form.expireDate"
                          clearable
                          placeholder="请选择有效期"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="小包装库存量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入小包装库存量"/>
        </el-form-item>
        <el-form-item label="机构ID" prop="orgId">
          <el-input v-model="form.orgId" placeholder="请输入机构ID"/>
        </el-form-item>
        <el-form-item label="货位" prop="location">
          <el-input v-model="form.location" placeholder="请输入货位"/>
        </el-form-item>
        <el-form-item label="创建时间" prop="invoiceDate">
          <el-date-picker v-model="form.invoiceDate"
                          clearable
                          placeholder="请选择创建时间"
                          type="datetime"
                          value-format="YYYY-MM-DD HH:mm:ss">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注信息" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注信息"/>
        </el-form-item>
        <el-form-item label="比例" prop="proportion">
          <el-input v-model="form.proportion" placeholder="请输入比例"/>
        </el-form-item>
        <el-form-item label="进价(小规格)" prop="tradePriceMin">
          <el-input v-model="form.tradePriceMin" placeholder="请输入进价(小规格)"/>
        </el-form-item>
        <el-form-item label="进价(小规格)" prop="retailPriceMin">
          <el-input v-model="form.retailPriceMin" placeholder="请输入进价(小规格)"/>
        </el-form-item>
        <el-form-item label="创建人姓名" prop="createByName">
          <el-input v-model="form.createByName" placeholder="请输入创建人姓名"/>
        </el-form-item>
        <el-form-item label="修改人姓名" prop="updateByName">
          <el-input v-model="form.updateByName" placeholder="请输入修改人姓名"/>
        </el-form-item>
        <el-form-item label="采购计划单号" prop="purchasingPlanNo">
          <el-input v-model="form.purchasingPlanNo" placeholder="请输入采购计划单号"/>
        </el-form-item>
        <el-form-item label="是否国采Y是 N否">
          <el-radio-group v-model="form.isNationalProcurement">
            <el-radio
              v-for="dict in sys_yes_no"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{ dict.dictLabel }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script lang="ts">
export default {
  name: "DrugPurchasingPlanItem"
}
</script>

<script lang="ts" setup>
import {
  addDrugPurchasingPlanItem,
  delDrugPurchasingPlanItem,
  getDrugPurchasingPlanItem,
  listDrugPurchasingPlanItem,
  updateDrugPurchasingPlanItem
} from "@/api/drug/drugPurchasingPlanItem";

import {useDictStoreHook} from "@/store/modules/dict";

const dictStore = useDictStoreHook();
let dictDataMap = ref(dictStore.isTypeGetData('spec_unit', 'sys_yes_no'))

const {proxy} = getCurrentInstance() as any;

const formRef = ref();
const queryParamsRef = ref()
const drugPurchasingPlanItemList = ref([]);
const open = ref(false);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");

const data = ref({
  form: {
    drugPurchasingPlanId: "",
    itemNo: "",
    drugCode: "",
    drugInfoId: "",
    packageNum: 0,
    packageSpec: "",
    packageUnits: "",
    minSpec: "",
    minUnits: "",
    packSize: "",
    tradePrice: 0,
    retailPrice: 0,
    batchNo: "",
    produceDate: "",
    expireDate: "",
    quantity: 0,
    orgId: "",
    location: "",
    invoiceDate: "",
    remarks: "",
    proportion: 0,
    tradePriceMin: 0,
    retailPriceMin: 0,
    createByName: "",
    updateByName: "",
    purchasingPlanNo: "",
    isNationalProcurement: ""
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    drugPurchasingPlanId: "",
    itemNo: "",
    drugCode: "",
    drugInfoId: "",
    packageNum: 0,
    packageSpec: "",
    packageUnits: "",
    minSpec: "",
    minUnits: "",
    packSize: "",
    tradePrice: 0,
    retailPrice: 0,
    batchNo: "",
    produceDate: "",
    expireDate: "",
    quantity: 0,
    orgId: "",
    location: "",
    invoiceDate: "",
    remarks: "",
    proportion: 0,
    tradePriceMin: 0,
    retailPriceMin: 0,
    createByName: "",
    updateByName: "",
    purchasingPlanNo: "",
    isNationalProcurement: ""
  },
  rules: {
    id: [
      {
        required: true, message: "主键不能为空", trigger: "blur"
      }
    ],
    drugPurchasingPlanId: [
      {
        required: true, message: "采购计划主表id不能为空", trigger: "blur"
      }
    ],
    drugCode: [
      {
        required: true, message: "药品编码不能为空", trigger: "blur"
      }
    ],
    drugInfoId: [
      {
        required: true, message: "药品字典drug_info id不能为空", trigger: "blur"
      }
    ],
    packageSpec: [
      {
        required: true, message: "包装规格不能为空", trigger: "blur"
      }
    ],
    packageUnits: [
      {
        required: true, message: "包装单位不能为空", trigger: "change"
      }
    ],
    minSpec: [
      {
        required: true, message: "最小规格不能为空", trigger: "blur"
      }
    ],
    minUnits: [
      {
        required: true, message: "最小单位不能为空", trigger: "change"
      }
    ],
    tradePrice: [
      {
        required: true, message: "进货价(批量入库的入库价,发放出库的零售价)不能为空", trigger: "blur"
      }
    ],
    batchNo: [
      {
        required: true, message: "批号不能为空", trigger: "blur"
      }
    ],
    orgId: [
      {
        required: true, message: "机构ID不能为空", trigger: "blur"
      }
    ],
    tradePriceMin: [
      {
        required: true, message: "进价(小规格)不能为空", trigger: "blur"
      }
    ],
    retailPriceMin: [
      {
        required: true, message: "进价(小规格)不能为空", trigger: "blur"
      }
    ],
  }
});

const {queryParams, form, rules} = toRefs(data.value);

/** 查询药品采购计划确认明细列表 */
function getList() {
  listDrugPurchasingPlanItem(queryParams.value).then((response: any) => {
    drugPurchasingPlanItemList.value = response.rows;
    total.value = response.total;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: "",
    drugPurchasingPlanId:
      "",
    itemNo:
      "",
    drugCode:
      "",
    drugInfoId:
      "",
    packageNum:
      0,
    packageSpec:
      "",
    packageUnits:
      "",
    minSpec:
      "",
    minUnits:
      "",
    packSize:
      "",
    tradePrice:
      0,
    retailPrice:
      0,
    batchNo:
      "",
    produceDate:
      "",
    expireDate:
      "",
    quantity:
      0,
    orgId:
      "",
    location:
      "",
    invoiceDate:
      "",
    delFlag:
      "",
    createBy:
      "",
    createTime:
      "",
    updateBy:
      "",
    updateTime:
      "",
    remarks:
      "",
    proportion:
      0,
    tradePriceMin:
      0,
    retailPriceMin:
      0,
    createByName:
      "",
    updateByName:
      "",
    purchasingPlanNo:
      "",
    isNationalProcurement:
      "0"
  }
  ;
  nextTick(() => {
    formRef.value.resetFields()
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  queryParamsRef.value.resetFields()
  // proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  if (!queryParams.value.orgId) {
    return ElMessage.error("请先选择机构")
  }
  open.value = true;
  reset();
  title.value = "添加药品采购计划确认明细";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  open.value = true;
  reset();
  const _id = row.id || ids.value
  getDrugPurchasingPlanItem(_id).then((response: any) => {
    form.value = response.data;
    title.value = "修改药品采购计划确认明细";
  });
}

/** 提交按钮 */
function submitForm() {
  (formRef.value as any).validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateDrugPurchasingPlanItem(form.value).then((response: any) => {
          ElMessage.success("修改成功");
          open.value = false;
          getList();
        }).finally(() => {
        });
      } else {
        addDrugPurchasingPlanItem(form.value).then((response: any) => {
          ElMessage.success("新增成功");
          open.value = false;
          getList();
        }).finally(() => {
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id ||
    ids.value;
  ElMessageBox.confirm('是否确认删除药品采购计划确认明细编号为"' + ids + '"的数据项？',
    {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning',
    }
  ).then(() => {
    delDrugPurchasingPlanItem(_ids).then(() => {
      getList();
      ElMessage.success("删除成功");
    })
  }).catch(() => {
  })
}


/** 导出按钮操作 */
function handleExport() {
  proxy.download('drug/drugPurchasingPlanItem/export', {
    ...queryParams.value
  }, `drugPurchasingPlanItem_${new Date().getTime()}.xlsx`)
}

getList();
</script>
